<?php 
namespace app\admin\controller;

use think\Controller;
use think\Request;
/**
 * 后台模块登录控制器
 */
class Login extends Controller
{
	//登录页面请求方法
	public function index(){

		return $this->fetch();
	} 

	//登录验证请求
	public function login(Request $request)
	{
		$admin=model('Admin');
		$userName=$request->param('userName');
		$passWord=$request->param('passWord');

		//使用数组查询
		$res=$admin::get(['userName'=>$userName,'passWord'=>$passWord]);

		if($res){
		    //更新时间戳
		    $res->last_login_time =   time();
            $res->save();

			session('admin',$res);
			$this->success('登录成功','Index/index');
		}else{
			 $this->error('登录失败');
		}
		
	}

	public function loginOut()
	{
		session('admin',null);
		$this->redirect('login/index');

	}

}

